package com.zhiyou100.video.service.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.zhiyou100.video.dao.CourseDao;
import com.zhiyou100.video.model.Course;
import com.zhiyou100.video.model.Subject;
import com.zhiyou100.video.model.Video;
import com.zhiyou100.video.service.CourseService;
import com.zhiyou100.video.utils.Page;
import com.zhiyou100.video.utils.TimeCycle;
@Controller
public class CourseServiceImpl implements CourseService {
	@Autowired
	CourseDao cd;
	@Override
	public Page<Course> selectCourse(Integer currentpage) {
		Integer count = cd.selectCourseConut();
		List<Course> list = cd.selectCourse(currentpage);
		Page<Course> page = new Page<Course>();
		page.setPage(currentpage);
		page.setRows(list);
		page.setSize(5);
		page.setTotal(count);
		return page;
	}
	@Override
	public List<Subject> selectSubject() {
		return cd.selectSubject();
	}
	@Override
	public void addCourse(Course course) {
		cd.addCourse(course);
	}
	@Override
	public Course selectCourseId(Integer id) {
		return cd.selectCourseId(id);
	}
	@Override
	public void deletecourse(Integer did) {
		cd.deletecourse(did);
	}
	@Override
	public List<Object[]> selectVideo() {
		return cd.selectVideo();
	}
	@Override
	public List<Course> selectIndexVideo(DetachedCriteria dc) {
		List<Course> list = cd.selectIndexVideo(dc);
		for (Course course : list) {
			for (Video video : course.getVideoSet()) {
				video.setVideoLengthStr(TimeCycle.send(video.getVideoLength()));
			}
		}
		return list;
	}
	@Override
	public List<Subject> selectvideoindex(DetachedCriteria dc) {
		return cd.selectvideoindex(dc);
	}
	@Override
	public void addViceoState(Integer videoId) {
		cd.addViceoState(videoId);
	}
	

}
